package cn.buk.tms.entity.bill;

import cn.buk.common.util.DecimalUtil;
import cn.buk.tms.entity.misc.Customer;
import com.fasterxml.jackson.annotation.JsonFormat;

import jakarta.persistence.*;
import java.util.Date;

@Entity
@Table(name = "settlement_sheet", uniqueConstraints = @UniqueConstraint(name = "uk_settlement", columnNames = {"enterprise_id", "settlement_no"}))
public class SettlementSheet {

    public static final int UNPAID = 0; // 未支付
    public static final int PAID = 1; // 已支付，已销账

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    @Column(name = "enterprise_id")
    private int enterpriseId;

    /**
     * 结算单号
     */
    @Column(name = "settlement_no", length = 50)
    private String settlementNo;


    /**
     * 客户类型
     * 0 - 代表散客
     * 1 - 代表企业客户
     */
    @Column(name="customer_type")
    private Integer customerType;

    /**
     * 客户id: 该结算单的客户
     */
    @ManyToOne
    @JoinColumn(name = "customer_id")
    private Customer customer;

    /**
     * 结算单名称：方便使用者区分
     */
    @Column(length = 50)
    private String name;

    /**
     * 该结算单客户是否已支付
     * 0-未支付
     * 1-已支付
     */
    private int paid;

    /**
     * 结算单金额
     */
    private double amount;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="create_time", insertable = false, updatable = false)
    private Date createTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @Temporal(TemporalType.TIMESTAMP)
    @Column(insertable = false)
    private Date lastUpdate;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getEnterpriseId() {
        return enterpriseId;
    }

    public void setEnterpriseId(int enterpriseId) {
        this.enterpriseId = enterpriseId;
    }

    public String getSettlementNo() {
        return settlementNo;
    }

    public void setSettlementNo(String settlementNo) {
        this.settlementNo = settlementNo;
    }

    public int getPaid() {
        return paid;
    }

    public void setPaid(int paid) {
        this.paid = paid;
    }

    public double getAmount() {
        return DecimalUtil.keepScale2(this.amount);
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getLastUpdate() {
        return lastUpdate;
    }

    public void setLastUpdate(Date lastUpdate) {
        this.lastUpdate = lastUpdate;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public Integer getCustomerType() {
        return customerType == null ? 1 : customerType;
    }

    public void setCustomerType(Integer customerType) {
        this.customerType = customerType;
    }
}
